package com.shoppeso.activity;

import android.app.Activity;
import android.os.Bundle;

import com.shoppeso.view.BaseWebView;
import com.mopub.mobileads.MoPubErrorCode;
import com.mopub.mobileads.MoPubView;
import com.shoppeso.R;

/**
 * Created by ChengZhi on 2016/3/30.
 */
public class MainActivity extends Activity implements MoPubView.BannerAdListener {
    private BaseWebView webView;
    private MoPubView mMoPubView, topMoPubView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
        initView();
    }

    private void initView() {
        final String adUnitId = "497c211508fb480386cb5e2a500c0f01";
        webView = (BaseWebView) findViewById(R.id.web_view);
        webView.loadByHead("http://www.shoppeso.com");
        mMoPubView = (MoPubView) findViewById(R.id.banner_mopubview);
        mMoPubView.setAdUnitId(adUnitId);
        mMoPubView.setAutorefreshEnabled(true);
        mMoPubView.loadAd();
        topMoPubView = (MoPubView) findViewById(R.id.top_banner_mopubview);
        topMoPubView.setAdUnitId(adUnitId);
        topMoPubView.setAutorefreshEnabled(true);
        topMoPubView.loadAd();
    }

    private void loadMoPubView(final String adUnitId, final String keywords) {

    }

    @Override
    public void onBannerLoaded(MoPubView banner) {

    }

    @Override
    public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {

    }

    @Override
    public void onBannerClicked(MoPubView banner) {

    }

    @Override
    public void onBannerExpanded(MoPubView banner) {

    }

    @Override
    public void onBannerCollapsed(MoPubView banner) {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mMoPubView != null) {
            mMoPubView.destroy();
            mMoPubView = null;
        }
        if (topMoPubView != null) {
            topMoPubView.destroy();
            topMoPubView = null;
        }
    }
}
